package com.yenn.barcode.otherdemo;

import com.yenn.barcode.otherdemo.MyQrCodeImage;
import jp.sourceforge.qrcode.QRCodeDecoder;
import lombok.extern.slf4j.Slf4j;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * #### 6-4 使用QR Code方式生成和解析二维码 (16:14)
 * QRCode
 * 1. 生成: http://www.swetake.com/qrcode/index.html
 * 2. 读取: https://osdn.jp/projects/qrcode/
 */
@Slf4j
public class ReadQrcode2 {

    public static void main(String[] args) {

        try {
            File file = new File("D:" + File.separator + "qrcode2.png");
            BufferedImage bufferedImage = ImageIO.read(file);
            QRCodeDecoder codeDecoder = new QRCodeDecoder();
            byte[] decode = codeDecoder.decode(new MyQrCodeImage(bufferedImage));
            String result = new String(decode);
            log.info("{}",result);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
